package edu.tsinghua.oxy.engineer.job;

import edu.tsinghua.oxy.engineer.service.IJobService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 处理URL
 *
 * @author sean
 * @date 2021 - 07 - 28 下午5:15
 */
@Slf4j
@Component
public class UrlJob extends QuartzJobBean {

    @Resource
    IJobService jobService;

    /**
     * 消费和生产URL的job
     * @param jobExecutionContext
     */
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        // 整个方法加上异常捕获，防止异常导致定时器崩溃
        try {
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            log.info("UrlJob----" + dtf.format(LocalDateTime.now()));
            jobService.flying();
        }catch (Exception e){
            log.error("UrlJob----运行时出现错误！！！",e);
        }
    }

}
